package com.study.service.test;

import com.study.service.impl.CarServiceImpl;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author chenhs
 * @date 2019/8/31
 */
public class testIoc {
	@Test
	public void testIOC() {
		/*普通方法实现*/
		CarServiceImpl carService = new CarServiceImpl();
		carService.showCar();
		
	}
	
	@Test
	public void testIOC2() {
		/*框架获取实例的方式*/
		
		/*
		 * 1：获取容器
		 * 2：获取实例
		 *
		 * */
		/*获取容器（容器只获取一次就好了）
		*
		* */
		String xmlPath = "main/resources/applicationContext.xml";
		final ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(xmlPath);
		/*获取到实体*/
		CarServiceImpl car = (CarServiceImpl) applicationContext.getBean("carId");
		car.showCar();
		
	}
	
}
